package com.neko.Thread_Learning;


/**
 * 1、定义1个【函数式接口 @FunctionalInterface】 -> 只有1个抽象方法
 * */
@FunctionalInterface
interface ILike {
    void lambda();

    /**
     * 加多1个【抽象方法】, 就不成立 @FunctionalInterface
     * */
//    void lambda2();
}

// 2、实现class
class Like implements ILike {

    @Override
    public void lambda() {
        System.out.println("I like lambda 1");
    }
}


public class t8_1_Lambda_Expression {

    // 3、静态内部类
    static class Like2 implements ILike {

        @Override
        public void lambda() {
            System.out.println("I like lambda 2");
        }
    }


    public static void main(String[] args) {

        ILike like = new Like();
        like.lambda();

        like = new Like2();
        like.lambda();

        // 4、局部内部类
        class Like3 implements ILike {
            @Override
            public void lambda() {
                System.out.println("I like lambda 3");
            }
        }

        like = new Like3();
        like.lambda();

        // 5、匿名内部类
        like = new Like() {
            @Override
            public void lambda() {
                System.out.println("I like lambda 4");
            }
        };
        like.lambda();

        // 5、用 lambda 简化
        like = () -> {
            System.out.println("I like lambda 5");
        };
        like.lambda();
    }

}




